home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performResetTransformations. < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.2 KB  |  377 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  27 Aug 1999
  22. //
  23. //  Description:
  24. //      Performs reset transformations on objects.
  25. //
  26. //
  27. //  Procedure Name:
  28. //      setOptionVars
  29. //
  30. //  Description:
  31. //        Initialize the option values.
  32. //
  33. //  Input Arguments:
  34. //        Whether to set the options to default values.
  35. //
  36. //  Return Value:
  37. //      None.
  38. //
  39. proc setOptionVars(int $forceFactorySettings)
  40. {
  41.     //    Add optionVar to store what's being reset - translate, rotate, or scale
  42.     //
  43.     if ($forceFactorySettings || !`optionVar -exists resetTransformationsTranslate`){
  44.         optionVar -intValue resetTransformationsTranslate 1;
  45.     }
  46.     if ($forceFactorySettings || !`optionVar -exists resetTransformationsRotate`){
  47.         optionVar -intValue resetTransformationsRotate 1;
  48.     }
  49.     if ($forceFactorySettings || !`optionVar -exists resetTransformationsScale`){
  50.         optionVar -intValue resetTransformationsScale 1;
  51.     }
  52. }
  53.  
  54. //
  55. //  Procedure Name:
  56. //      performResetTransformationsSetup
  57. //
  58. //  Description:
  59. //        Update the state of the option box UI to reflect the option values.
  60. //
  61. //  Input Arguments:
  62. //      parent               - Top level parent layout of the option box UI.
  63. //                             Required so that UI object names can be 
  64. //                             successfully resolved.
  65. //
  66. //    forceFactorySettings - Whether the option values should be set to
  67. //                             default values.
  68. //
  69. //  Return Value:
  70. //      None.
  71. //
  72. global proc performResetTransformationsSetup(string $parent, 
  73.     int $forceFactorySettings)
  74. {
  75.     // Retrieve the option settings
  76.     //
  77.     setOptionVars ($forceFactorySettings);
  78.     setParent $parent;
  79.  
  80.     //    Radio button to select what gets moved
  81.     //
  82.     int $trans = `optionVar -q resetTransformationsTranslate`;
  83.     int $rotate = `optionVar -q resetTransformationsRotate`;
  84.     int $scale = `optionVar -q resetTransformationsScale`;
  85.  
  86.     checkBoxGrp -e -v1 $trans resetCheckBoxGrp;
  87.     checkBoxGrp -e -v2 $rotate resetCheckBoxGrp;
  88.     checkBoxGrp -e -v3 $scale resetCheckBoxGrp;
  89. }
  90.  
  91. //
  92. //  Procedure Name:
  93. //      performResetTransformationsCallback
  94. //
  95. //  Description:
  96. //        Update the option values with the current state of the option box UI.
  97. //
  98. //  Input Arguments:
  99. //      parent - Top level parent layout of the option box UI.  Required so
  100. //               that UI object names can be successfully resolved.
  101. //
  102. //    doIt   - Whether the command should execute.
  103. //
  104. //  Return Value:
  105. //      None.
  106. //
  107. global proc performResetTransformationsCallback(string $parent, int $doIt)
  108. {
  109.     setParent $parent;
  110.  
  111.     // Set the optionVar's from the control values, and then perform command
  112.     //
  113.     int $i = `checkBoxGrp -q -v1 resetCheckBoxGrp`;
  114.     optionVar -intValue resetTransformationsTranslate $i;
  115.     $i = `checkBoxGrp -q -v2 resetCheckBoxGrp`;
  116.     optionVar -intValue resetTransformationsRotate $i;
  117.     $i = `checkBoxGrp -q -v3 resetCheckBoxGrp`;
  118.     optionVar -intValue resetTransformationsScale $i;
  119.  
  120.     if ($doIt) {
  121.         performResetTransformations 0; 
  122.         addToRecentCommandQueue "performResetTransformations 0" "ResetTransformations";
  123.     }
  124. }
  125.  
  126. //
  127. //  Procedure Name:
  128. //      performResetTransformationsOptions
  129. //
  130. //  Description:
  131. //        Construct the option box UI.  Involves accessing the standard option
  132. //        box and customizing the UI accordingly.
  133. //
  134. //  Input Arguments:
  135. //      None.
  136. //
  137. //  Return Value:
  138. //      None.
  139. //
  140. proc performResetTransformationsOptions()
  141. {
  142.     //    Name of the command for this option box.
  143.     //
  144.     string $commandName = "performResetTransformations";
  145.  
  146.     //    Build the option box actions.
  147.     //
  148.     string $callback = ($commandName + "Callback");
  149.     string $setup = ($commandName + "Setup");
  150.  
  151.     //    STEP 1:  Get the option box.
  152.     //    ============================
  153.     //
  154.     //    The value returned is the name of the layout to be used as
  155.     //    the parent for the option box UI.
  156.     //
  157.     string $layout = getOptionBox();
  158.     setParent $layout;
  159.     
  160.     //    STEP 2:  Pass the command name to the option box - see STEP 8.
  161.     //    ==============================================================
  162.     
  163.     //    STEP 3:  Activate the default UI template.
  164.     //    ==========================================
  165.     //
  166.     //    Activate the default UI template so that the layout of this 
  167.     //    option box is consistent with the layout of the rest of the 
  168.     //    application.
  169.     //
  170.     setUITemplate -pushTemplate DefaultTemplate;
  171.  
  172.     //    STEP 4: Create option box contents.
  173.     //    ===================================
  174.     //    
  175.     //    This, of course, will vary from option box to option box.    
  176.     
  177.     //    Turn on the wait cursor.
  178.     //
  179.     waitCursor -state 1;
  180.  
  181.     //    RECOMMENDATION:  Place the UI in a 'scrollable' layout.  A 
  182.     //    scrollable layout ensures that if the option box window is ever
  183.     //    resized such that it's entire contents is not visible then the 
  184.     //    scroll bars provided by the scrollable layout will allow the user
  185.     //    to access the hidden UI.  Two layouts currently supporting 
  186.     //    scrollable behaviour are the 'scrollLayout' and the 'tabLayout'.
  187.     //
  188. //    scrollLayout;
  189.     //
  190.     //    or...
  191.     //
  192.     tabLayout -tabsVisible 0 -scrollable 1;
  193.     
  194.     string $parent = `columnLayout -adjustableColumn 1`;
  195.     
  196.     //    RECOMMENDATION:  Use the 'Grp' commands where possible because
  197.     //    they obey the formatting specified in the default template.
  198.     //    This will result in a more consistent look throughout the
  199.     //    application.
  200.     //    
  201.  
  202.     checkBoxGrp -label "Reset"  -ncb 3
  203.         -label1 "Translate"
  204.         -label2 "Rotate"
  205.         -label3 "Scale"
  206.         resetCheckBoxGrp;
  207.  
  208.     //    Turn off the wait cursor.
  209.     //
  210.     waitCursor -state 0;
  211.     
  212.     //    Step 5: Deactivate the default UI template.
  213.     //    ===========================================
  214.     //
  215.     setUITemplate -popTemplate;
  216.  
  217.     //    Step 6: Customize the buttons.  
  218.     //    ==============================
  219.     //
  220.     //    Provide more descriptive labels for the buttons.  This is not 
  221.     //    necessary, but in some cases, for example, a button labelled 
  222.     //    'Create' may be more meaningful to the user than one labelled
  223.     //    'Apply'.
  224.     //
  225.     //    Disable those buttons that are not applicable to the option box.
  226.     //
  227.     //    Attach actions to those buttons that are applicable to the option
  228.     //    box.  Note that the 'Close' button has a default action attached 
  229.     //    to it that will hide the window.  If a a custom action is
  230.     //    attached to the 'Close' button then be sure to call the 'hide the
  231.     //    option box' procedure within the custom action so that the option
  232.     //    box is hidden properly.
  233.  
  234.     //    'Apply' button.
  235.     //
  236.     string $applyBtn = getOptionBoxApplyBtn();
  237.     button -edit
  238.         -label "Reset Transform"
  239.         -command ($callback + " " + $parent + " " + 1)
  240.         $applyBtn;
  241.  
  242.     //    'Save' button.
  243.     //
  244.     string $saveBtn = getOptionBoxSaveBtn();
  245.     button -edit 
  246.         -command ($callback + " " + $parent + " " + 0 + "; hideOptionBox")
  247.         $saveBtn;
  248.  
  249.     //    'Reset' button.
  250.     //
  251.     string $resetBtn = getOptionBoxResetBtn();
  252.     button -edit 
  253.         -command ($setup + " " + $parent + " " + 1)
  254.         $resetBtn;
  255.  
  256.     //    Step 7: Set the option box title.
  257.     //    =================================
  258.     //
  259.     setOptionBoxTitle("Reset Transformations Options");
  260.  
  261.     //    Step 8: Customize the 'Help' menu item text.
  262.     //    ============================================
  263.     //
  264.     setOptionBoxHelpTag( "ResetTransformations" );
  265.  
  266.     //    Step 9: Set the current values of the option box.
  267.     //    =================================================
  268.     //
  269.     eval (($setup + " " + $parent + " " + 0));    
  270.     
  271.     //    Step 10: Show the option box.
  272.     //    =============================
  273.     //
  274.     showOptionBox();
  275. }
  276.  
  277. //
  278. //  Procedure Name:
  279. //      performParentHelp
  280. //
  281. //  Description:
  282. //        Return a short description about this command.
  283. //
  284. //  Input Arguments:
  285. //      None.
  286. //
  287. //  Return Value:
  288. //      string.
  289. //
  290. proc string performParentHelp()
  291. {
  292.     return 
  293.     "  Command: Reset Transformations.\n" +
  294.     " will reset the select object's transformations to identity.";
  295. }
  296.  
  297. //
  298. //  Procedure Name:
  299. //      assembleCmd
  300. //
  301. //  Description:
  302. //        Construct the command that will apply the option box values.
  303. //
  304. //  Input Arguments:
  305. //      None.
  306. //
  307. proc string assembleCmd()
  308. {
  309.     string  $cmd = "makeIdentity";
  310.  
  311.     setOptionVars(false);
  312.  
  313.     int        $trans      = `optionVar -q resetTransformationsTranslate`;
  314.     int        $rotate      = `optionVar -q resetTransformationsRotate`;
  315.     int        $scale      = `optionVar -q resetTransformationsScale`;
  316.     
  317.     // Execute the command with the option settings
  318.     //
  319.  
  320.     $cmd = $cmd+ "-apply false" +
  321.         " -t "+$trans +" -r " + $rotate + " -s " + $scale;
  322.     return $cmd;
  323. }
  324.  
  325. //
  326. //  Procedure Name:
  327. //      performParent
  328. //
  329. //  Description:
  330. //        Perform the performParent command using the corresponding 
  331. //        option values.  This procedure will also show the option box
  332. //        window if necessary as well as construct the command string
  333. //        that will invoke the optionBoxExample1 command with the current
  334. //        option box values.
  335. //
  336. //  Input Arguments:
  337. //      0 - Execute the command.
  338. //      1 - Show the option box dialog.
  339. //      2 - Return the command.
  340. //
  341. global proc string performResetTransformations(int $action)
  342. {
  343.     string $cmd = "";
  344.  
  345.     switch ($action) {
  346.  
  347.         //    Execute the command.
  348.         //
  349.         case 0:
  350.             //    Get the command.
  351.             //
  352.             $cmd = `assembleCmd`;
  353.  
  354.             //    Execute the command with the option settings.
  355.             //
  356.             eval($cmd);
  357.  
  358.             break;
  359.  
  360.         //    Show the option box.
  361.         //
  362.         case 1:
  363.             performResetTransformationsOptions;
  364.             break;
  365.  
  366.         //    Return the command string.
  367.         //
  368.         case 2:
  369.             //    Get the command.
  370.             //
  371.             $cmd = `assembleCmd`;
  372.             break;
  373.     }
  374.     return $cmd;
  375. }
  376.  
  377.